/**
 * Author:   anTi
 * Date:     2018/11/29 11:08
 * Description:
 * version: 1.0
 */

package com.imooc.avtiviti.interceptor;

import org.activiti.engine.impl.interceptor.AbstractCommandInterceptor;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//获取执行时间
public class DurationCommandInterceptor extends AbstractCommandInterceptor {
    private static final Logger LOGGER = LoggerFactory.getLogger(DurationCommandInterceptor.class);

    @Override
    public <T> T execute(CommandConfig commandConfig, Command<T> command) {
        //记录开始时间
        long startTime = System.currentTimeMillis();
        try {
            return this.getNext().execute(commandConfig,command);
        }finally {
            long duration = System.currentTimeMillis() - startTime;
            LOGGER.info("{} 执行时间 {} 毫秒",command.getClass().getSimpleName(),duration);
        }

    }
}
